﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Team6_Algorithms.Filters;
//written by Pascal Schotman
namespace VisionApplication
{

    class SaltPepper : VisionAlgorithm
    {
        
        public SaltPepper(String name, string[] required) : base(name,required)
        {
            
        }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage, Object obj)
        {
            Bitmap returnImage = new Bitmap(sourceImage);

            //copy to snell class for fast access
            FastPixelAccess retImg = new FastPixelAccess(returnImage);

            //lock images for use
            retImg.Lock();
            int number = ((retImg.Width * retImg.Height) / 100) * settings.Percentage;

            //set black and white color
            Random rnd = new Random();

            int x, y = 0;
            //random pixel times number
            for (int i = 0; i < number; i++)
            {
                x = rnd.Next(retImg.Width);
                y = rnd.Next(retImg.Height);
                int color = rnd.Next(1, 3);
                if (color == 1)
                {
                    retImg.SetPixel(x, y, Color.White);
                }
                else
                {
                    retImg.SetPixel(x, y, Color.Black);
                }
            }
            //unlock and return image for showing
            retImg.Unlock(true);
            this.Image = returnImage;
            return returnImage;
        }
    }
}